package com.xunwulian.cmeb.command;

import com.xunwulian.base.constant.CmebCardStatus;
import com.xunwulian.base.exception.ErrorCodeException;
import org.json.JSONArray;

/**
 * 开关机状态查询
 */
public class UserStatusCommand extends Command {

    private String msisdn;

    public UserStatusCommand(Receiver receiver, String msisdn) {
        super(APICode.USERSTATUS, receiver);
        this.msisdn = msisdn;
    }

    @Override
    public String getParam() {
        return "msisdn=" + msisdn;
    }

    @Override
    public String execute() throws ErrorCodeException {
        JSONArray result = receiver.actionPost(api, getParam());

        String status = CmebCardStatus.UNKNOWN.getType();
        if (null != result && result.length() != 0) {
            status = result.getJSONObject(0).getString("status");
        }
        return status;
    }
}
